package cn.wyj.dao;

import cn.wyj.domain.Comment;
import cn.wyj.utils.Commons;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommentMapper {
    /**
     * 分页查询某个文章的评论
     * @param articleId
     * @return
     */
    @Select("select *from comment where article_id=#{articleId} order by id DESC ")
    List<Comment>  findCommentByPage(Integer articleId);

    /**
     * 查询最新几条评论
     * @return
     */
    @Select("select *from comment order by id DESC")
    List<Comment> findNewComment();

    /**
     * 发表评论
     * @param comment
     */
    @Insert("insert into comment(article_id,created,author,ip,content) values (#{articleId}," +
            "#{created},#{author},#{ip},#{content})")
    void addComment(Comment comment);

    /**
     * 统计评论数量
     * @return
     */
    @Select("select count(1) from comment")
    Integer getTotalComment();

    /**
     * 通过文章id删除评论信息
     * @param aid
     */
    @Delete("delete from comment where article_id =#{aid}")
    void delCommentByAid(Integer aid);
}
